package cn.edu.hqu.cst.android.firstexperiment;

import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.GridLayout;

import androidx.appcompat.app.AppCompatActivity;

public class GridActivity extends AppCompatActivity {
    GridLayout gridLayout;
    String[] chars = new String[]
            {
                    "1","2","3",
                    "4","5","6",
                    "7","8","9",
                    "0","+","-",
                    "*","/","=",
                    //"7","8","9","/",
                    //"4","5","6","*",
                    //"1","2","3","-",
                    //".","0","=","+",
            };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_grid);
        gridLayout = (GridLayout)findViewById(R.id.root);
        for(int i = 0 ; i < chars.length ; i++)
        {
            Button bn = new Button(this);
            bn.setText(chars[i]);
            bn.setTextSize(40);
            bn.setPadding(5,35,5,35);
            GridLayout.Spec rowSpec = GridLayout.spec(i/3+2,1f);
            GridLayout.Spec columnSpec = GridLayout.spec(i%3,1f);
            GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpec,columnSpec);
            params.setGravity(Gravity.FILL);
            gridLayout.addView(bn,params);
        }
        Button btn2 = (Button)findViewById(R.id.button2);
        btn2.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                Intent i = new Intent(GridActivity.this , MainActivity.class);
                startActivity(i);
            }
        });
    }
}
